﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace RSSReader
{
    [XmlRoot("RSSItems", Namespace = "RSSItems", IsNullable = false)]
    public class RSSItems
    {
        public List<RSSItem> Items { get; set; }

        public void Add(object item)
        {
            Items.Add((RSSItem)item);
        }

        public RSSItems()
        {
            Items = new List<RSSItem>();
        }

        public void AddItems(RSSItems items)
        {
            Items.AddRange(items.Items);
        }

        public void AddItem(RSSItem item)
        {
            Items.Add(item);
        }
    }


    public enum AddState
    {
        NotFound,
        FoundAndAdded,
        FoundAndAlreadyExists
    }

    public class RSSItem
    {
        public string Title { get; set; }
        public int Season { get; set; }
        public int Episode { get; set; }
        public DateTime PubDate { get; set; }
        public string URL { get; set; }
        public bool Found { get; set; }
        public bool IsSeries { get; set; }
        public AddState State { get; set; }

        public RSSItem()
        {
            Found = false;
            State = AddState.NotFound;
            IsSeries = false;
        }

        public override string ToString()
        {
            string itemText = "Title: " + Title;
            if (IsSeries)
            {
                itemText += ". Season: " + Season + ". Episode: " + Episode;
            }
            itemText += ". Published on: " + PubDate.ToString("dd/MM/yyyy HH:mm:ss");
                    
            switch (State)
            {
                case AddState.NotFound:
                    itemText = DateTime.Now + ": Didn't find (or error during search) " + itemText;
                    break;
                case AddState.FoundAndAdded:
                    itemText = DateTime.Now + ": Added " + itemText;
                    break;
                case AddState.FoundAndAlreadyExists:
                    itemText = DateTime.Now + ": Older or already exists - not adding " + itemText;
                    break;

            }
            return itemText;
        }

        public RSSItem(string title, int season, int episode, DateTime pubDate, string url)
        {
            Title = title;
            Season = season;
            Episode = episode;
            PubDate = pubDate;
            URL = url;
            State = AddState.NotFound;
            Found = false;
            IsSeries = true;
        }

        public RSSItem(string title, DateTime pubDate, string url)
        {
            Title = title;
            PubDate = pubDate;
            URL = url;
            IsSeries = false;
        }
    }


}
